﻿
@{
    ViewData["Title"] = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<style>
    .el-tag + .el-tag {
        margin-left: 10px;
    }

    .button-new-tag {
        margin-left: 10px;
        height: 32px;
        line-height: 30px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .input-new-tag {
        width: 90px;
        margin-left: 10px;
        vertical-align: bottom;
    }

    .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
        margin-bottom: 10px !important;
    }
</style>
<div id="divForm" style="margin:2px;padding:2px;" v-cloak>
    <el-form :model="form" label-width="150px" style="top:80px;">
        <div style="top:20px;position:fixed;height:80px;left:45px;">
            <el-row :gutter="24">

                <el-button type="primary" v-on:click="SaveGlobalConfiguration()" size="mini">保存</el-button>
                <el-button v-on:click="Back()" size="mini">返回</el-button>

            </el-row>
        </div>
        <el-card class="box-card" style="margin-top: 50px;" size="mini">
            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="域名" size="mini">
                        <el-input v-model="form.baseUrl" autocomplete="off" size="mini"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="请求id的Key" size="mini">
                        <el-input v-model="form.requestIdKey" autocomplete="off" size="mini"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="下游协议" size="mini">
                        <el-radio-group v-model="form.downstreamScheme" size="mini">
                            <el-radio label='https'>https</el-radio>
                            <el-radio label='http'>http</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="下游http版本" size="mini">
                        <el-input v-model="form.downstreamHttpVersion" autocomplete="off" placeholder="1.0, 1.1 or 2.0" size="mini"></el-input>
                    </el-form-item>
                </el-col>
            </el-row> 
            <el-row :gutter="24">
                <el-tabs> 
                    <el-tab-pane label="服务发现">
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="状态" size="mini">
                                    <el-radio-group v-model="form.serviceDiscoveryEnabled" size="mini">
                                        <el-radio :label="true">启用</el-radio>
                                        <el-radio :label="false">禁用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                         
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="协议" size="mini"> 
                                    <el-radio-group v-model="form.serviceDiscovery_Scheme" size="mini">
                                        <el-radio label='https'>https</el-radio>
                                        <el-radio label='http'>http</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="Host" size="mini">
                                    <el-input v-model="form.serviceDiscovery_Host" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="端口" size="mini">
                                    <el-input v-model="form.serviceDiscovery_Port" type="number" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="类型" size="mini">
                                    <el-input v-model="form.serviceDiscovery_Type" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="Token" size="mini">
                                    <el-input v-model="form.serviceDiscovery_Token" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="ConfigurationKey" size="mini">
                                    <el-input v-model="form.serviceDiscovery_ConfigurationKey" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="轮询间隔" size="mini">
                                    <el-input v-model="form.serviceDiscovery_PollingInterval" type="number" autocomplete="off" size="mini">
                                        <template slot="append">
                                            毫秒
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="命名空间" size="mini">
                                    <el-input v-model="form.serviceDiscovery_Namespace" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>
                    <el-tab-pane label="断路器配置">
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="状态" size="mini">
                                    <el-radio-group v-model="form.qosEnabled" size="mini">
                                        <el-radio :label="true">启用</el-radio>
                                        <el-radio :label="false">禁用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>

                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="8">
                                <el-form-item label="允许的例外数量" size="mini">
                                    <el-input v-model="form.qos_ExceptionsAllowedBeforeBreaking" placeholder="打开断路器之前允许的例外数量" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="恢复时间间隔" size="mini">
                                    <el-input v-model="form.qos_DurationOfBreak" placeholder="断路器复位之前，打开的时间" autocomplete="off" size="mini">
                                        <template slot="append">
                                            毫秒
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="请求超时时间" size="mini">
                                    <el-input v-model="form.qos_TimeoutValue" placeholder="请求超时时间" autocomplete="off" size="mini">
                                        <template slot="append">
                                            毫秒
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>
                    <el-tab-pane label="流量限制">
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="包含X-Rate-Limit和Rety-After" size="mini">
                                    <el-radio-group v-model="form.rateLimit_DisableRateLimitHeaders" size="mini">
                                        <el-radio :label="true">禁用</el-radio>
                                        <el-radio :label="false">启用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="客户Header" size="mini">
                                    <el-input v-model="form.rateLimit_ClientIdHeader" placeholder="ClientId" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="超过限制提示语" size="mini">
                                    <el-input v-model="form.rateLimit_QuotaExceededMessage"  autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="计数前缀" size="mini">
                                    <el-input v-model="form.rateLimit_RateLimitCounterPrefix" placeholder="ocelot" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="超过限制Http状态码" size="mini">
                                    <el-input v-model="form.rateLimit_HttpStatusCode"  type="number"  autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>

                    <el-tab-pane label="http处理">
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="允许自定重定向" size="mini">
                                    <el-radio-group v-model="form.httpHandler_AllowAutoRedirect" size="mini">
                                        <el-radio :label="true">允许</el-radio>
                                        <el-radio :label="false">不允许</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="使用cookie容器" size="mini">
                                    <el-radio-group v-model="form.httpHandler_UseCookieContainer" size="mini">
                                        <el-radio :label="true">使用</el-radio>
                                        <el-radio :label="false">不使用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="使用追踪" size="mini">
                                    <el-radio-group v-model="form.httpHandler_UseTracing" size="mini">
                                        <el-radio :label="true">使用</el-radio>
                                        <el-radio :label="false">不使用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="使用代理" size="mini">
                                    <el-radio-group v-model="form.httpHandler_UseProxy" size="mini">
                                        <el-radio :label="true">使用</el-radio>
                                        <el-radio :label="false">不使用</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="服务最大连接数" size="mini">
                                    <el-input v-model="form.httpHandler_MaxConnectionsPerServer" type="number" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>
                    <el-tab-pane label="负载均衡">
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="负载均衡类型" size="mini">
                                    <el-radio-group v-model="form.loadBalancer_Type" size="mini">
                                        <el-radio label="RoundRobin" value="RoundRobin">轮询</el-radio>
                                        <el-radio label="LeastConnection" value="LeastConnection">最少连接数</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="负载均衡Key" size="mini">
                                    <el-input v-model="form.loadBalancer_Key" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="12">
                                <el-form-item label="负载均衡Expiry" size="mini">
                                    <el-input v-model="form.loadBalancer_Expiry" type="number" autocomplete="off" size="mini"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>


                </el-tabs>
            </el-row>

</el-form>
</div>
<script>

    var vueNewsCategory = new Vue({
        el: '#divForm',
        data() {
            return {

                rateWhiteLists: [],
                rateWhiteListVisible: false,
                rateWhiteListValue: '',

                allowedScopes: [],
                scopeVisible: false,
                scopeValue: '',


                headerTableData:[],
                headerTransformTableData:[],
                headerDownTransformTableData: [],
                claimsTableData: [],

                claimsRouteTableData: [],
                queriesTableData:[],
                downTempletesTableData: [],
                hostPortTableData:[],

                form: {
                    id: parseInt(getQueryString("id") || 0),
                    projectId:0,
                    dangerousAcceptAnyServerCertificateValidator:false,
                    upstreamHttpMethodList: [],
                    downstreamScheme:'',
                    loadBalancer_Type:''
                }
            }
        },
        created() {
            var _this = this;

            _this.GetGlobalConfiguration();
        },
        methods: {
             
            GetGlobalConfiguration() {
                var _this = this;
                _this.$get("@Url.Action("GetGlobalConfiguration", "GlobalConfiguration")?id=" + _this.form.id ).then((res) => {
                    _this.form = res;

                    _this.rateWhiteLists = res.rateLimit_WhiteList_list||[];
                    _this.form.upstreamHttpMethodList = res.upstreamHttpMethodList||[];
                    _this.allowedScopes = res.authentication_AllowedScopes_List || [];
                    _this.headerTableData = res.headers || [];
                    _this.headerTransformTableData = res.headerUpTransforms || [];
                    _this.headerDownTransformTableData = res.headerDownTransform || [];
                    _this.claimsTableData = res.claims || [];
                    _this.claimsRouteTableData = res.routeClaims || [];
                    _this.queriesTableData = res.queries || [];
                    _this.downTempletesTableData = res.downTempletes || [];
                    _this.hostPortTableData = res.hostPort || [];
                    _this.security_IPBlockedList_List = res.security_IPBlockedList_List || [];
                    _this.security_IPAllowedList_List = res.security_IPAllowedList_List || [];
                });
            },
            SaveGlobalConfiguration() {
                var _this = this; 
                _this.$post("@Url.Action("SaveGlobalConfiguration", "GlobalConfiguration")", _this.form).then((res) => {
                    _this.$success(res.message, function () {
                   
                    });
                });
            },

            Back() {
                this.$back();
            }
        }
    });
</script>

